package com.mind.adjust.service.impl;

import com.mind.customer.mapper.AjDatasourceMapper;
import com.mind.system.domain.AjDatasource;
import com.mind.adjust.service.AjDatasourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 数据源(AjDatasource)表服务实现类
 *
 * @author makejava
 * @since 2024-10-24 09:59:34
 */
@Service("datasourceService")
public class AjDatasourceServiceImpl implements AjDatasourceService {
    @Autowired
    private AjDatasourceMapper datasourceMapper;

    /**
     * 查询数据源信息集合
     * 
     * @param datasource 数据源信息
     * @return 数据源信息集合
     */
    @Override
    public List<AjDatasource> selectDatasourceList(AjDatasource datasource)
    {
        return datasourceMapper.selectDatasourceList(datasource);
    }

    /**
     * 通过数据源ID查询数据源信息
     * 
     * @param datasourceId 数据源ID
     * @return 角色对象信息
     */
    @Override
    public AjDatasource selectDatasourceById(Long datasourceId)
    {
        return datasourceMapper.selectDatasourceById(datasourceId);
    }

    /**
     * 删除数据源信息
     * 
     * @param datasourceId 数据源ID
     * @return 结果
     */
    @Override
    public int deleteDatasourceById(Long datasourceId)
    {
        return datasourceMapper.deleteDatasourceById(datasourceId);
    }

    /**
     * 批量删除数据源信息
     * 
     * @param datasourceIds 需要删除的数据源ID
     * @return 结果
     */
    @Override
    public int deleteDatasourceByIds(Long[] datasourceIds)
    {
        return datasourceMapper.deleteDatasourceByIds(datasourceIds);
    }

    /**
     * 新增保存数据源信息
     * 
     * @param datasource 数据源信息
     * @return 结果
     */
    @Override
    public int insertDatasource(AjDatasource datasource)
    {
        return datasourceMapper.insertDatasource(datasource);
    }

    /**
     * 修改保存数据源信息
     * 
     * @param datasource 数据源信息
     * @return 结果
     */
    @Override
    public int updateDatasource(AjDatasource datasource)
    {
        return datasourceMapper.updateDatasource(datasource);
    }
    
    /**
     * 批量插入
     *
     * @param datasourceList 附件类型信息
     * @return 结果
     */
    @Override
    public int batchInsert(List<AjDatasource> datasourceList) {
        int size = 0;
        for(AjDatasource datasource: datasourceList) {
            if (datasourceMapper.selectDatasourceByName(datasource.getName()) == null){
                datasourceMapper.insertDatasource(datasource);
                size ++;
            }
        }
        return size;
    }
}
